package com.study.hot.jetpack.demo_words.viewmodel;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;

import com.study.hot.jetpack.demo_words.db.Words;
import com.study.hot.jetpack.demo_words.db.WordsRepository;

import java.util.List;

/**
 * <pre>
 *     author : slx
 *     time   : 2020/03/31
 *     desc   :
 * </pre>
 */
public class WordsViewModel extends AndroidViewModel {

    private WordsRepository wordsRepository;

    public WordsViewModel(@NonNull Application application) {
        super(application);
        wordsRepository = WordsRepository.newInstance(application);
    }

    public void insertWords(Words... words) {
        wordsRepository.insertWords(words);
    }

    public void deleteWords(Words... words) {
        wordsRepository.deleteWords(words);
    }

    public void updateWords(Words... words) {
        wordsRepository.updateWords(words);
    }

    public void deleteAllWords() {
        wordsRepository.deleteAllWords();
    }

    public LiveData<List<Words>> getAllWords() {
        return wordsRepository.getAllWords();
    }

    public LiveData<List<Words>> getWordsByEnglish(String english) {
        return wordsRepository.getWordsByEnglish(english);
    }
}
